<?php
	session_start();
	require_once '../models/Product.php';
	define("FILE_URL",$_SERVER['PHP_SELF']);
	
?>
<!DOCTYPE html>
<html>
<head>
<form action="search.php" method="get" >
<title>Shop Online</title>
<?php include '_meta.php';?>
</head>
<body>
	<div id="firstLine">
		<div id="top-bar">
		<?php include '_top_bar.php';?>
		</div>
	</div>
	<div id="warp">
	<div id="container">
		<div id="header">
			<?php include '_head.php';?>
		</div>
		<?php include '_menu_head.php';?>
		<div id="center">
			<div id="menu-left">
				<?php include '_menu_left.php';?>
			</div>
			<div id="table">
				<!--<div id="spdh">Sản phẩm đang hot</div>-->
				<div id="table-head">
				<?php
				if(isset($_GET['key']) and strlen($_GET['key'])>2) {
				$key = addslashes(htmlspecialchars(trim($_GET['key'])));
				$sql = "SELECT
						pr.productID,
						md.modelName,
						sr.seriesName,
						pr.image,
						pr.price,
						br.brandName
						FROM
						tbl_brand AS br ,
						tbl_model AS md ,
						tbl_series AS sr ,
						tbl_product AS pr,
						tbl_product_detail dt
						WHERE
						pr.productID=dt.productID AND
						br.brandID = pr.brandID AND
						pr.modelID = md.modelID AND
						pr.seriesID = sr.seriesID AND
						CONCAT(br.brandName,md.modelName,sr.seriesName) LIKE '%$key%'
						ORDER BY br.brandName DESC";
				$rs = mysql_query($sql)or die ("show: ".mysql_error());;
						if (@mysql_num_rows($rs)>0) {
							while ($pro = mysql_fetch_assoc($rs)) {
							print('<li class="sp">
								<a href=productDetail.php?productID='.$pro['productID'].'>
									<div><img src='.$pro['image'].'></div>
									<div  class="name"><span>'.$pro['brandName'].' '.$pro['modelName'].' '.$pro['seriesName'].'</span></div>
									<div class="price"><span>'.number_format($pro['price'],3).' VND</span></div>
								</a>
								</li>');}
							print('</ul></div>');
							}else echo "<br><br><br>Không rõ kết quả ! Từ khóa nhập vào phải cách nhau khoảng trắng";
						} else {
							 echo "<br><br><br>Không rõ kết quả ! Từ khóa nhập vào phải cách nhau khoảng trắng";
						}
			?>
				</div>
    		</form>
    	</div>
    <br />
	</div>
</div>
<div id="footer">
<?php

include '_footer.php';

?>
</div>